#
# This file is part of Sonedyan.
# 
# Sonedyan is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 3 of the License, or (at your option) any
# later version.
#
# Sonedyan is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public
# License along with Octave; see the file COPYING.  If not
# see <http://www.gnu.org/licenses/>.
# 
# Copyright (C) 2009-2014 Jimmy Dubuisson <jimmy.dubuisson@gmail.com>
#

from utils import *

g = Graph.Read_GraphML('g_d.xml')

writer = FilteredMemoryWriter(3)
c = Cycles(g, writer, 3)

c.log.setLevel(logging.INFO)
ch = logging.StreamHandler()
#ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
c.log.addHandler(ch)

c.cycles()

ig = get_intersection_graph(g,writer.cycles)

cid = ig.vs(name_eq='fight.conflict.war')[0].index
cids = ig.subcomponent(cid)

igs = ig.subgraph(cids)

cls = igs.cliques(min=4)

gcl=[]
for cl in cls:
        for i in cl:
                vn = igs.vs(i)['name'][0]
                if 'conflict' in vn:
                        if len(cl) > len(gcl):
                                gcl = cl
                                break

print gcl
igc = igs.induced_subgraph(gcl)

ig.write_gml("igs.gml")
ig.write_graphml("igs.xml")

igs.write_gml("igs.gml")
igs.write_graphml("igs.xml")

igc.write_gml("igc.gml")
igc.write_graphml("igc.xml")
